package com.lizhangjun.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lizhangjun.domain.QGoodsCategory;
import com.lizhangjun.entity.Result;
import com.lizhangjun.service.QGoodsCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lizhangjun
 * @since 2021-06-23
 */
@Api(tags = {"商品分类相关接口"} )
@RestController
@RequiredArgsConstructor
@RequestMapping("/q-goods-category")
public class QGoodsCategoryController {

    private final QGoodsCategoryService goodsCategoryService;

    /**
     * 查找所有商品分类
     * @return 查找所有商品分类
     */
    @ApiOperation("查找所有商品分类")
    @GetMapping("/list")
    public Result list(){
        return Result.success(goodsCategoryService.list());
    }

    /**
     * 查找前8个热门商品分类
     * @return 频道
     */
    @ApiOperation("查找前8个热门商品分类")
    @GetMapping("/top")
    public Result top(){
        LambdaQueryWrapper<QGoodsCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.last("limit 8");
        return Result.success(goodsCategoryService.list(wrapper));
    }
}

